library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
NGS <- read_csv("NGS.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
##   .default = col_double()
## )
## See spec(...) for full column specifications.
NGS_Small <-NGS
df <- NGS_Small %>%
  filter(SEX != "0" & totcorr !=7 & SMOKE != "0") %>%
  filter(ETHNIC !="0" & ETHNIC != "7") %>% 
  filter(decage !="0") %>%
  #Now we are averaging by sex and age
  group_by(SEX,decage) %>% 
  summarize(totcorr = mean(totcorr))
## `summarise()` regrouping output by 'SEX' (override with `.groups` argument)
ggplot(df, aes(x = decage, y = totcorr, color=as.factor(SEX)))+
  geom_point()

ggplot(df, aes(x = decage, y = totcorr, color=as.factor(SEX)))+
  geom_point()+
  labs(y="Number Correct")+
  scale_color_manual(name="Sex",labels=c("Male","Female"),values=c("blue","red"))+
  scale_x_continuous(name="Age in Decades",breaks=c(1:9),labels=c("Teens","20's","30's","40's","50's","60's","70's","80's","90's"))

library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
AS<-ggplot(df, aes(x = decage, y = totcorr, color=as.factor(SEX)))+
  geom_point(aes(frame = decage))+
  labs(y="Number Correct")+
  scale_color_manual(name="Sex",labels=c("Male","Female"),values=c("blue","pink"))+
  scale_x_continuous(name="Age in Decades",breaks=c(1:9),labels=c("Teens","20's","30's","40's","50's","60's","70's","80's","90's"))+
   theme_classic()
## Warning: Ignoring unknown aesthetics: frame
ggplotly(AS)